<template>
  <div>
    <el-table
      :data="menuList"
      style="width: 100%"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="菜单编号"></el-table-column>
      <el-table-column prop="title" label="菜单名称"></el-table-column>
      <el-table-column label="菜单图标">
        <template slot-scope="scope">
          <div>
            <i :class="scope.row.icon"></i>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="菜单地址"></el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="success" v-if="scope.row.status == 1"
              >启 用</el-button
            >
            <el-button type="danger" v-else>禁 用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="primary" plain @click="edit(scope.row.id)"
              >编 辑</el-button
            >
            <!-- <el-button type="primary" @click="del(scope.row.id)">删 除</el-button> -->
            <v-del @del="del(scope.row.id)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { successAlert, warningAlert } from "../../../util/alert";
import { menuDel } from "../../../request/api";
export default {
  props: [],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      menuList: "menu/list",
    }),
  },
  methods: {
    ...mapActions({
      reqMenuList: "menu/reqChangeList",
    }),
    //封装版本删除
    del(id) {
      menuDel({ id: id }).then((res) => {
        if (res.data.code == 200) {
          //删除成功弹窗
          successAlert(res.data.msg);
          //重新请求列表数据
          this.reqMenuList();
        } else {
          //删除失败弹窗
          warningAlert(res.data.msg);
        }
      });
    },
    //删除
    // del(id){
    //   //.then说明点了确定         .catch说明点了取消
    //   this.$confirm("此操作将永久删除该文件,是否继续?", "提示", {
    //     confirmButtontext: "确定",
    //     cancelButtonText: "取消",
    //     type: "success",
    //   })
    //     .then(() => {
    //       //当你点击了确定的时候才会走.then
    //       menuDel({ id: id }).then(res => {
    //         if (res.data.code == 200) {
    //           //删除成功弹窗
    //           successAlert(res.data.msg);
    //           //重新请求列表数据
    //           this.reqMenuList();
    //         } else {
    //           //删除失败弹窗
    //           warningAlert(res.data.msg);
    //         }
    //       });
    //     })
    //     .catch(() => {
    //       warningAlert("已取消删除");
    //     });
    // },
    //编辑
    edit(id) {
      this.$emit("edit", id);
    },
  },
  mounted() {
    this.reqMenuList();
  },
};
</script>

<style scoped>
</style>